#include "OutputManager.h"

const QString OutputManager::SECTION_HEADER_TITLE_FRONT_TAG = "<table width = \"100%\"><tr><td align = \"left\"><span style=\" font-size:15pt; font-weight:600;\">";
const QString OutputManager::SECTION_HEADER_TITLE_BACK_TAG = "</td></span>";
const QString OutputManager::SECTION_HEADER_DATE_FRONT_TAG = "<td align = \"right\"><span style=\" font-size:10pt; color:grey;\">";
const QString OutputManager::SECTION_HEADER_DATE_BACK_TAG = "</td></span></tr></table><br><br>";
const QString OutputManager::SECTION_HEADER_ONLYONE_BACK_TAG = "</tr></table><br><br>";

/*Top Bottom
const QString OutputManager::SECTION_COMPONENT_NAME_FRONT_TAG_NORMAL = "<p><span style=\" font-size:10pt; font-weight:600;\">";
const QString OutputManager::SECTION_COMPONENT_NAME_BACK_TAG_NORMAL = "</span><br>";
const QString OutputManager::SECTION_COMPONENT_DATEORTIME_FRONT_TAG_NORMAL = "<span style=\" font-size:8pt; color:grey;\">";
const QString OutputManager::SECTION_COMPONENT_DATEORTIME_END_TAG_NORMAL = "</span></p>";
const QString OutputManager::SECTION_COMPONENT_ONLYONE_BACK_TAG_NORMAL = "</p>";

const QString OutputManager::SECTION_COMPONENT_NAME_FRONT_TAG_ADDITION = "<p><span style=\" font-size:10pt; font-weight:600; color:green;\">";
const QString OutputManager::SECTION_COMPONENT_NAME_BACK_TAG_ADDITION = "</span><br>";
const QString OutputManager::SECTION_COMPONENT_DATEORTIME_FRONT_TAG_ADDITION = "<span style=\" font-size:8pt; color:green;\">";
const QString OutputManager::SECTION_COMPONENT_DATEORTIME_END_TAG_ADDITION = "</span></p>";
const QString OutputManager::SECTION_COMPONENT_ONLYONE_BACK_TAG_ADDITION = "</p>";

const QString OutputManager::SECTION_COMPONENT_NAME_FRONT_TAG_CLASH = "<p><span style=\" font-size:10pt; font-weight:600; color:red;\">";
const QString OutputManager::SECTION_COMPONENT_NAME_BACK_TAG_CLASH = "</span><br>";
const QString OutputManager::SECTION_COMPONENT_DATEORTIME_FRONT_TAG_CLASH = "<span style=\" font-size:8pt; color:red;\">";
const QString OutputManager::SECTION_COMPONENT_DATEORTIME_END_TAG_CLASH = "</span></p>";
const QString OutputManager::SECTION_COMPONENT_ONLYONE_BACK_TAG_CLASH = "</p>";

*/

//Left Right

const QString OutputManager::SECTION_COMPONENT_NAME_FRONT_TAG_NORMAL = "<table width = \"100%\"><tr><td align = \"left\"><span style=\" font-size:10pt; font-weight:600;\">";
const QString OutputManager::SECTION_COMPONENT_NAME_BACK_TAG_NORMAL = "</td></span>";
const QString OutputManager::SECTION_COMPONENT_DATEORTIME_FRONT_TAG_NORMAL = "<td align = \"right\"><span style=\" font-size:8pt; color:grey;\">";
const QString OutputManager::SECTION_COMPONENT_DATEORTIME_END_TAG_NORMAL = "</td></span></tr></table><br>";
const QString OutputManager::SECTION_COMPONENT_ONLYONE_BACK_TAG_NORMAL = "</tr></table><br>";


const QString OutputManager::SECTION_COMPONENT_NAME_FRONT_TAG_ADDITION = "<table width = \"100%\"><tr><td align = \"left\"><span style=\" font-size:10pt; font-weight:600; color: green;\">";
const QString OutputManager::SECTION_COMPONENT_NAME_BACK_TAG_ADDITION = "</td></span>";
const QString OutputManager::SECTION_COMPONENT_DATEORTIME_FRONT_TAG_ADDITION = "<td align = \"right\"><span style=\" font-size:8pt; color:green;\">";
const QString OutputManager::SECTION_COMPONENT_DATEORTIME_END_TAG_ADDITION = "</td></span></tr></table><br>";
const QString OutputManager::SECTION_COMPONENT_ONLYONE_BACK_TAG_ADDITION = "</tr></table><br>";


const QString OutputManager::SECTION_COMPONENT_NAME_FRONT_TAG_CLASH = "<table width = \"100%\"><tr><td align = \"left\"><span style=\" font-size:10pt; font-weight:600; color:red;\">";
const QString OutputManager::SECTION_COMPONENT_NAME_BACK_TAG_CLASH = "</td></span>";
const QString OutputManager::SECTION_COMPONENT_DATEORTIME_FRONT_TAG_CLASH = "<td align = \"right\"><span style=\" font-size:8pt; color:red;\">";
const QString OutputManager::SECTION_COMPONENT_DATEORTIME_END_TAG_CLASH = "</td></span></tr></table><br>";
const QString OutputManager::SECTION_COMPONENT_ONLYONE_BACK_TAG_CLASH = "</tr></table><br>";

const QString OutputManager::SECTION_COMPONENT_NAME_FRONT_TAG_DONE = "<table width = \"100%\"><tr><td align = \"left\"><span style=\" font-size:10pt; font-weight:600;\"><s>";
const QString OutputManager::SECTION_COMPONENT_NAME_BACK_TAG_DONE = "</td></span></s>";
const QString OutputManager::SECTION_COMPONENT_DATEORTIME_FRONT_TAG_DONE = "<td align = \"right\"><span style=\" font-size:8pt;\"><s>";
const QString OutputManager::SECTION_COMPONENT_DATEORTIME_END_TAG_DONE = "</td></span></tr></table><br></s>";
const QString OutputManager::SECTION_COMPONENT_ONLYONE_BACK_TAG_DONE = "</tr></table><br>";

OutputManager::OutputManager(vector<vector<CommonUtils::ReturnString>> outputFromManager)
{
	_vectOfVectOfStrings = outputFromManager;
}


OutputManager::~OutputManager(void)
{
}


QString OutputManager::getFormattedString()
{
	convertToOutputStr();
	return _formattedOutput;
}


QString OutputManager::appendSectionHeaderTags(pair<string, string> entry){
	
	QString appendedHeader;
	//The name will always be there
	assert(entry.first != "");

	if(entry.second != ""){

		appendedHeader += SECTION_HEADER_TITLE_FRONT_TAG;
		appendedHeader += QString::fromStdString(entry.first);
		appendedHeader += SECTION_HEADER_TITLE_BACK_TAG;
		appendedHeader += SECTION_HEADER_DATE_FRONT_TAG;
		appendedHeader += QString::fromStdString(entry.second);
		appendedHeader += SECTION_HEADER_DATE_BACK_TAG;
	}
	else{

		appendedHeader += SECTION_HEADER_TITLE_FRONT_TAG;
		appendedHeader += QString::fromStdString(entry.first);
		appendedHeader += SECTION_HEADER_TITLE_BACK_TAG;
		appendedHeader += SECTION_HEADER_ONLYONE_BACK_TAG;

	}

	return appendedHeader;

}

QString OutputManager::appendNormalComponentTags(pair<string, string> entry){

		QString appendedNormalComponent;
	//The name will always be there
	assert(entry.first != "");

	if(entry.second != ""){
		appendedNormalComponent += SECTION_COMPONENT_NAME_FRONT_TAG_NORMAL;
		appendedNormalComponent += QString::fromStdString(entry.first);
		appendedNormalComponent += SECTION_COMPONENT_NAME_BACK_TAG_NORMAL;
		appendedNormalComponent += SECTION_COMPONENT_DATEORTIME_FRONT_TAG_NORMAL;
		appendedNormalComponent += QString::fromStdString(entry.second);
		appendedNormalComponent += SECTION_COMPONENT_DATEORTIME_END_TAG_NORMAL;

	}
	else{

		appendedNormalComponent += SECTION_COMPONENT_NAME_FRONT_TAG_NORMAL;
		appendedNormalComponent += QString::fromStdString(entry.first);
		appendedNormalComponent += SECTION_COMPONENT_NAME_BACK_TAG_NORMAL;
		appendedNormalComponent += SECTION_COMPONENT_ONLYONE_BACK_TAG_NORMAL;

	}

	return appendedNormalComponent;
}

QString OutputManager::appendAdditionComponentTags(pair<string, string> entry){
	
	QString appendedAdditionComponent;
	//The name will always be there
	assert(entry.first != "");

	if(entry.second != ""){
		appendedAdditionComponent += SECTION_COMPONENT_NAME_FRONT_TAG_ADDITION;
		appendedAdditionComponent += QString::fromStdString(entry.first);
		appendedAdditionComponent += SECTION_COMPONENT_NAME_BACK_TAG_ADDITION;
		appendedAdditionComponent += SECTION_COMPONENT_DATEORTIME_FRONT_TAG_ADDITION;
		appendedAdditionComponent += QString::fromStdString(entry.second);
		appendedAdditionComponent += SECTION_COMPONENT_DATEORTIME_END_TAG_ADDITION;

	}
	else{

		appendedAdditionComponent += SECTION_COMPONENT_NAME_FRONT_TAG_ADDITION;
		appendedAdditionComponent += QString::fromStdString(entry.first);
		appendedAdditionComponent += SECTION_COMPONENT_NAME_BACK_TAG_ADDITION;
		appendedAdditionComponent += SECTION_COMPONENT_ONLYONE_BACK_TAG_ADDITION;

	}

	return appendedAdditionComponent;

}

QString OutputManager::appendClashComponentTags(pair<string, string> entry){
		
	QString appendedClashComponent;
	//The name will always be there
	assert(entry.first != "");

	if(entry.second != ""){
		appendedClashComponent += SECTION_COMPONENT_NAME_FRONT_TAG_CLASH;
		appendedClashComponent += QString::fromStdString(entry.first);
		appendedClashComponent += SECTION_COMPONENT_NAME_BACK_TAG_CLASH;
		appendedClashComponent += SECTION_COMPONENT_DATEORTIME_FRONT_TAG_CLASH;
		appendedClashComponent += QString::fromStdString(entry.second);
		appendedClashComponent += SECTION_COMPONENT_DATEORTIME_END_TAG_CLASH;

	}
	else{

		appendedClashComponent += SECTION_COMPONENT_NAME_FRONT_TAG_CLASH;
		appendedClashComponent += QString::fromStdString(entry.first);
		appendedClashComponent+= SECTION_COMPONENT_NAME_BACK_TAG_CLASH;
		appendedClashComponent += SECTION_COMPONENT_ONLYONE_BACK_TAG_CLASH;

	}

	return appendedClashComponent;

}
QString OutputManager::appendDoneComponentTags(pair<string, string> entry){
		
	QString appendedDONEComponent;
	//The name will always be there
	assert(entry.first != "");

	if(entry.second != ""){
		appendedDONEComponent += SECTION_COMPONENT_NAME_FRONT_TAG_DONE;
		appendedDONEComponent += QString::fromStdString(entry.first);
		appendedDONEComponent += SECTION_COMPONENT_NAME_BACK_TAG_DONE;
		appendedDONEComponent += SECTION_COMPONENT_DATEORTIME_FRONT_TAG_DONE;
		appendedDONEComponent += QString::fromStdString(entry.second);
		appendedDONEComponent += SECTION_COMPONENT_DATEORTIME_END_TAG_DONE;

	}
	else{

		appendedDONEComponent += SECTION_COMPONENT_NAME_FRONT_TAG_DONE;
		appendedDONEComponent += QString::fromStdString(entry.first);
		appendedDONEComponent+= SECTION_COMPONENT_NAME_BACK_TAG_DONE;
		appendedDONEComponent += SECTION_COMPONENT_ONLYONE_BACK_TAG_DONE;

	}

	return appendedDONEComponent;

}
void OutputManager::convertToOutputStr()
{
	for(int i = 0; i < _vectOfVectOfStrings.size(); i++)
	{
		_formattedOutput += convertEachSectionToStr(_vectOfVectOfStrings[i]);
	}

}

QString OutputManager::convertEachSectionToStr(vector<CommonUtils::ReturnString> section)
{


	QString sectionOutputString;
	sectionOutputString += appendSectionHeaderTags(section[0].entry);

	for(int i = 1; i < section.size(); i++){

		sectionOutputString += appendTagsForEachData(section[i]);
	}

	return sectionOutputString;
}

QString OutputManager::appendTagsForEachData(CommonUtils::ReturnString data){

	QString dataString;

	switch(data.format){

			//default format
	case CommonUtils::DISPLAY_FORMAT_DEFAULT:
	default:{ 
				dataString +=appendNormalComponentTags(data.entry);
				break;
			}
			//addition of items
	case CommonUtils::DISPLAY_FORMAT_NEW:{
				dataString += appendAdditionComponentTags(data.entry);
				break;

			}
			
			//clash of items
	case CommonUtils::DISPLAY_FORMAT_CLASH:{
				dataString += appendClashComponentTags(data.entry);
				break;
			}
			
	case CommonUtils::DISPLAY_FORMAT_COMPLETED:{
				dataString += appendDoneComponentTags(data.entry);
				break;
			}
	}

	return dataString;

}